package com.linxianqin.springbootVue.domain.model;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.linxianqin.springbootVue.domain.dto.SysDeptDTO;
import com.linxianqin.springbootVue.domain.dto.SysMenuDTO;
import com.linxianqin.springbootVue.domain.entity.SysDept;
import com.linxianqin.springbootVue.domain.entity.SysMenu;
import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author lxq
 * @version 1.0
 * @description: TreeSelect树结构实体类
 * @date 2020/12/16 11:21
 */
@Getter
@Setter
public class TreeSelect implements Serializable
{
    private static final long serialVersionUID = 1L;

    /** 节点ID */
    private Long id;

    /** 节点名称 */
    private String label;

    /** 子节点 */
    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    private List<TreeSelect> children;

    public TreeSelect() { }

    public TreeSelect(SysDeptDTO deptDTO)
    {
        this.id = deptDTO.getDeptId();
        this.label = deptDTO.getDeptName();
        this.children = deptDTO.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList());
    }

    public TreeSelect(SysMenuDTO menuDTO)
    {
        this.id = menuDTO.getMenuId();
        this.label = menuDTO.getMenuName();
        this.children = menuDTO.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList());
    }

}

